package com.dkm.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.dkm.entity.Users;
import com.dkm.service.MessageService;
import com.dkm.service.UsersService;
import com.dkm.util.ResultUtil;

@RestController
@RequestMapping("/message")
public class MessageController {

	//注入消息业务层
	@Autowired
	private MessageService messageService;
	//注入用户业务层
	@Autowired
	private UsersService usersService;
	
	@GetMapping("/getUserAndMessages")
	public List<Users> getUserMessages(String cur_user_id) {
		//获取全部用户
		List<Users> users=usersService.getAllUsers();
		
		System.out.println(users.size());
		//根据其他用户和当前用户的关系获取消息集合
		return messageService.getUserMessages(cur_user_id, users);
	}
	
	@PostMapping
	public ResultUtil addMessage(String sender_id,String content,String receiver_id) {
		
		return messageService.addMessage(sender_id, content, receiver_id);
	}
}
